package finger.dao.impl;

import finger.dao.OrderDao;
import finger.domain.Order;
import finger.web.BaseServlet;

import java.util.List;

public class OrderDaoImpl extends BaseDao implements OrderDao {
    @Override
    public void saveOrder(Order order) {
        String sql = "insert into t_order(`order_id`,`create_time`,`price`,`status`,`user_id`) values(?,?,?,?,?)";
        update(sql, order.getOrderId(), order.getCreateTime(), order.getPrice(), order.getStatus(), order.getUserId());
    }

    @Override
    public List<Order> queryMyOrders(int id) {
        String sql = "SELECT `order_id` orderId,create_time createTime,price,`status`,`user_id` userId FROM t_order WHERE user_id = ?";
        return getQueryForList(Order.class, sql, id);
    }

    @Override
    public List<Order> queryAllOrders() {
        String sql = "SELECT `order_id` orderId,create_time createTime,price,`status`,`user_id` userId FROM t_order where `status`=0" ;
        return getQueryForList(Order.class, sql);
    }

    @Override
    public void changeOrderStatus(Integer status, String orderId) {
        String sql = "UPDATE t_order SET `status` = ? WHERE order_id=?";
        update(sql, status, orderId);
    }
}
